class Solution:
    def maxRotateFunction(self, A) -> int:
        allSum = sum(A)
        nowSum = 0
        n = len(A)
        for i in range(n):
            nowSum += i*A[i]
        maxSum = nowSum
        for i in range(n-1,0,-1):
            nowSum = nowSum + allSum - n*A[i]
            maxSum = max(maxSum, nowSum)
        return maxSum


if __name__ == '__main__':
    so = Solution()
    A = [4, 3, 2, 6]
    r = so.maxRotateFunction(A)
    print(r)

